package servlet;

import dao.StudentD;
import vo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/update_student_security")
public class update_student_security extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");

        PrintWriter out = response.getWriter();
        StudentD studentD = new StudentD();

        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String stusex = request.getParameter("stusex");
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        System.out.println("密码："+password);
        try {
            if(password==""){
                Student student = studentD.updateStudentSecurity(id,name,stusex, email);
                request.getSession().setAttribute("info",student);
                out.print("<script>alert('修改成功');window.location.href='student/personal.jsp';</script>");
            }else {
                Student student = studentD.updateStudentSecurity(id,name,stusex, email, password);
                request.getSession().setAttribute("info",student);
                out.print("<script>alert('修改成功');window.location.href='login.jsp';</script>");
            }
        }
        catch (Exception e){
            out.print(e);
        }
    }

}
